package com.fudan.cfg.action;

import java.util.Map;

import com.fudan.cfg.base.ActionDef;
import com.fudan.run.ctx.annotation.ActionAdapter;

@ActionAdapter("upsert-to-es")
public class UpsertToEs  extends ActionDef{
	
	private String index;
	private String host;
	private String port;
	private String id;

	public UpsertToEs(String name, String type, String target) {
		super(name, type, target);
	}

	@Override
	public ActionDef build(Map<String, Object> configuration) {
		this.setIndex((String) configuration.get("index"));
		String hostStr = (String) configuration.get("host");
		String[] hostPair = hostStr.split(":");
		if(hostPair.length == 1) {
			this.host = hostPair[0];
			this.port = "9200";
		}
		if(hostPair.length == 2) {
			this.host = hostPair[0];
			this.port = hostPair[1];
		}
		this.id = (String) configuration.get("id");
		return this;
	}

	public String getIndex() {
		return index;
	}

	public void setIndex(String index) {
		this.index = index;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

}
